<template>
	<view class="container">
		<!-- 订单状态筛选 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="status-item" :class="{active: activeStatus === index}" v-for="(item, index) in statusList" :key="index" @click="switchStatus(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="card mb-20" v-for="(item, index) in orderList" :key="index">
				<view class="flex justify-between mb-20">
					<text style="font-weight: bold;">订单号: {{ item.orderNo }}</text>
					<text class="text-red">{{ item.status }}</text>
				</view>
				
				<view class="flex mb-20" @click="goToDetail(item)">
					<image :src="item.image" mode="aspectFill" style="width: 150rpx; height: 150rpx; border-radius: 10rpx;"></image>
					<view style="flex: 1; margin-left: 20rpx;">
						<text class="block">{{ item.title }}</text>
						<text class="block text-gray mt-10">数量: {{ item.quantity }}</text>
						<text class="block text-gray mt-10">时间: {{ item.time }}</text>
					</view>
				</view>
				
				<view class="flex justify-between">
					<text class="text-gray">总价: ¥{{ item.totalPrice }}</text>
					<view>
						<text class="button-line" style="padding: 10rpx 20rpx; font-size: 24rpx; margin-right: 20rpx;" v-if="item.status === '待付款'">取消订单</text>
						<text class="button" style="padding: 10rpx 20rpx; font-size: 24rpx;" v-if="item.status === '待付款'">立即支付</text>
						<text class="button" style="padding: 10rpx 20rpx; font-size: 24rpx;" v-if="item.status === '已付款'">查看订单</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-container text-center" v-if="orderList.length === 0">
			<text class="iconfont icon-order" style="font-size: 100rpx; color: #ccc;"></text>
			<text class="block mt-20">暂无订单</text>
			<text class="block text-gray mt-10">快去下单吧</text>
			<view class="button mt-20" @click="goToHome">去首页逛逛</view>
		</view>
		
		<!-- 使用自定义tabbar组件 -->
		<custom-tabbar :current-index="1"></custom-tabbar>
	</view>
</template>

<script>
// 引入自定义tabbar组件
	import CustomTabbar from '@/components/custom-tabbar/custom-tabbar.vue';
	
	export default {
		components: {
			CustomTabbar
		},
		data() {
			return {
				activeStatus: 0,
				statusList: ['全部', '待付款', '已付款', '已完成', '已取消'],
				orderList: [
					{
						id: 1,
						orderNo: '20230615001',
						title: '故宫博物院门票',
						image: '/static/gugong.jpg',
						quantity: 2,
						time: '2023-06-15 14:30',
						totalPrice: 120,
						status: '待付款'
					},
					{
						id: 2,
						orderNo: '20230610002',
						title: '北京环球影城一日票',
						image: '/static/huanqiu.jpg',
						quantity: 3,
						time: '2023-06-10 09:15',
						totalPrice: 1584,
						status: '已付款'
					}
				]
			}
		},
		methods: {
			switchStatus(index) {
				this.activeStatus = index;
				// 实际开发中这里需要重新请求对应状态的订单数据
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/order/detail?id=' + item.id
				})
			},
			goToHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.status-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.status-item.active {
		background: #4caf50;
		color: #fff;
	}
	
	.button-line {
		border: 1rpx solid #007AFF;
		color: #007AFF;
		border-radius: 10rpx;
		text-align: center;
	}
	
	.empty-container {
		padding-top: 200rpx;
	}
</style>